#pragma once
# include <string>
# include <functional>
# include <vector>
# include <mutex>
# include "Enums.h"
#include "concurrentqueue.h"

namespace ZDSJ {
	class LogStreamInterface;
	class LogFile;
	class Work;

	class Logger {
		friend class Log;
	public:
		static Logger* getInstance();
		const std::vector<std::string>& getSupport() const;
		static const LogStreamInterface* getStreamPtr();
		const LogStreamInterface* getStreamPtr(const std::string& _file_name, int _max_size = 1024, bool _loop = true, OverflowStratgy _stratgy = OverflowStratgy::overflow);
		bool empty() const;
		bool alive() const;

	private:
		Logger(const Logger&) = delete;
		Logger& operator=(const Logger&) = delete;
		Logger(Logger&&) = delete;
		Logger& operator=(Logger&&) = delete;

		std::vector<std::string> m_support;
		std::vector<LogFile*> m_file_stream;
		std::mutex m_mutex;
		std::condition_variable m_condition_variable;

		void work(const std::string& _log, std::vector<LogStreamInterface*> _workers);

		void threadWordFunc();

		moodycamel::ConcurrentQueue<Work*> m_queue;

		std::thread* m_thread = nullptr;

		std::atomic_bool m_alive = false;
	protected:
		Logger();

		~Logger();
	};

}